<template>
  <div class="order">
    <ohead title="订单确定"></ohead>
    <span class="sspan" @click="arrshow"></span>
    <ul>
      <li class="site">
        <span id="sspan">{{ msg }}</span>
        <p @click="show">
          <img src="../../../../static/images/cart/cart02.png" alt="" />
        </p>
      </li>
      <li class="commodity" v-for="(item, index) in diandanshuju" :key="index">
        <p class="text">{{ item.dpName }}</p>
        <div>
          <div class="Left">
            <img :src="item.cShopImgSrc" alt="" />
          </div>
          <div class="Right">
            <p class="text-1">
              {{ item.title }}
            </p>
            <p class="text-2">{{ item.ctype }}</p>
            <span>￥{{ item.price }}</span>
          </div>
        </div>
      </li>
      <li class="way">
        <div class="waybox">
          <div class="wayleft">
            <span>配送方式</span>
            <span class="text-3">普通快递</span>
          </div>
          <div class="wayright">
            <span class="sright">快递免邮</span>
            <img src="../../../../static/images/cart/cart02.png" alt="" />
          </div>
        </div>
        <div class="waybox">
          <div class="wayleft">
            <span>订单备注</span>
            <span class="text-3">请填写备注</span>
          </div>
        </div>
        <div class="subtotal">
          <span class="stext">共{{ countNum }}件</span>
          <span>小计：</span>
          <span>￥{{ zongjia.toFixed(2) }}</span>
        </div>
      </li>
      <li class="deduction">
        <p>树叶支付</p>
        <span>使用0树叶抵扣0.00元</span>
      </li>
    </ul>
    <a href="#">提示：使用树叶支付收取手续费10%，枫叶最多抵扣订单金额的90%</a>
    <footer class="footer">
      <div>
        <p>合计:</p>
        <span>￥{{ zongjia.toFixed(2) }}</span>
        <button @click="isShow">去支付</button>
      </div>
    </footer>
    <div class="pay" v-show="Show">
      <div class="box">
        <div>
          <span>选择支付方式</span>
          <span @click="isShow" class="right"
            ><img src="../../../../static/images/cart/cart07.png" alt=""
          /></span>
        </div>
        <span>￥{{ zongjia.toFixed(2) }}</span>
        <div>
          <p class="left">
            <img src="../../../../static/images/cart/zfb.png" alt="" />
            <span>支付宝</span>
          </p>
          <input type="radio" name="pay" />
        </div>
        <div>
          <p class="left">
            <img src="../../../../static/images/cart/wx.png" alt="" />
            <span>微信</span>
          </p>
          <input type="radio" name="pay" />
        </div>
        <button class="btn">立即付款</button>
      </div>
    </div>
  </div>
</template>

<script>
import ohead from "./orderhead";
import { Dialog } from 'vant';
export default {
  components: { ohead },
  data() {
    return {
      Show: false,
      diandanshuju: [],
      countNum: 0, //商品总数
      zongjia: 0,
      list: null,
      msg: "请选择收货地址",
    };
  },
  methods: {
    isShow() {
      if (!localStorage.getItem("shouhuoaddress")) {
        Dialog.alert({
          message: "请选择收货地址",
        }).then(() => {
          // on close
        });
        return;
      } else {
        console.log(1);
        this.Show = !this.Show;
        if (this.Show == false) {
          this.$router.push("/myorder");
        }
      }

      // this.$router.push('/myorder')
    },
    show() {
      this.$router.push("/address");
    },
    arrshow() {
      this.$router.push("/shop");
    },
  },
  mounted() {
    console.log(this.$store.state.shopcart);
    let obj = JSON.parse(localStorage.getItem("shangpindata"));
    this.diandanshuju = obj;
    console.log(obj);
    let count = 0;
    let zongjia = 0;
    this.diandanshuju.forEach((item) => {
      count += item.num;
      zongjia += item.num * item.price;
    });
    this.countNum = count;
    this.zongjia = zongjia;
    console.log(count);
    //
    this.list = JSON.parse(localStorage.getItem("shouhuoaddress"));
    if (!this.list) {
      return;
    } else {
      this.msg = this.list.name + "     " + this.list.tel;
      console.log(this.list);
      console.log(this.msg);
    }
  },
};
</script>

<style lang="less" scoped>
.pay {
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.2);
  position: fixed;
  top: 0;
  .box {
    width: 100%;
    height: 60vh;
    background-color: #fff;
    position: fixed;
    bottom: 0;
    border-radius: 20px;
    z-index: 99;
    div {
      text-align: center;
      position: relative;
      overflow: hidden;
      margin: 0;
      padding: 0;
      padding: 10px 0;
      span {
        font-size: 28px;
      }
      .right {
        img {
          height: 30px;
          position: absolute;
          float: left;
          right: 30px;
          top: 30px;
        }
      }
      img {
        height: 40px;
      }
      .left {
        float: left;
        img {
          float: left;
          margin: 18px;
        }
      }
      input {
        float: right;
        margin: 30px;
      }
    }
    .btn {
      width: 80vw;
      height: 70px;
      background-color: red;
      border: none;
      border-radius: 8px;
      font-size: 25px;
      color: #fff;
      margin-top: 250px;
    }
  }
}
.order {
  .sspan {
    position: fixed;
    top: 0;
    left: 0;
    width: 100px;
    height: 60px;
  }
  ul {
    li {
      margin-bottom: 20px;
      background-color: #fff;
      font-size: 25px;
      &.site {
        overflow: hidden;
        font-size: 30px;
        display: flex;
        padding: 30px 20px;
        background-color: #fff;
        span {
          display: inline-block;
          width: 400px;
        }
        p {
          width: 69%;
          overflow: hidden;
          text-align: right;
          img {
            width: 20px;
          }
        }
      }
      &.commodity {
        overflow: hidden;
        background-color: #fff;
        padding: 20px 20px;
        display: flex;
        flex-wrap: wrap;
        .text {
          font-size: 30px;
          text-align: left;
          margin-bottom: 20px;
          width: 100%;
        }
        .Left {
          float: left;
          margin-right: 20px;
          img {
            width: 200px;
          }
        }
        .Right {
          font-size: 25px;
          position: relative;
          p {
            padding-right: 50px;
            font-size: 29px;
            text-align: left;

            &.text-2 {
              background-color: #f5f5f5;
              display: inline-block;
              margin: 5px 0;
            }
          }
          span {
            display: block;
            text-align: left;
            position: absolute;
            bottom: -70px;
            left: 215px;
            font-size: 30px;
            color: red;
          }
        }
      }
      &.way {
        font-size: 25px;
        padding: 10px 20px;
        overflow: hidden;
        .waybox {
          overflow: hidden;
          padding: 15px 0;
          text-align: left;
          .wayleft {
            float: left;
            .text-3 {
              color: #b8b8b8;
              margin-left: 10px;
            }
          }
          .wayright {
            float: right;
            img {
              width: 20px;
              margin-top: 0;
              float: right;
            }
            .sright {
              margin-right: 40px;
            }
          }
        }
        .subtotal {
          float: right;
          margin-top: 25px;
          padding-bottom: 25px;
          span {
            &:nth-of-type(1) {
              color: gray;
            }
            &:nth-of-type(3) {
              color: rgba(211, 12, 12, 0.801);
            }
          }
        }
      }
      &.deduction {
        padding: 20px;
        display: flex;
        margin-bottom: 0;
      }
    }
  }
  a {
    font-size: 12px;
    color: #007acc;
  }
  .footer {
    position: fixed;
    bottom: 0px;
    overflow: hidden;
    width: 100%;
    //   height: 95px;
    padding: 30px;
    background-color: #fff;
    div {
      font-size: 28px;
      display: flex;
      span {
        color: red;
      }
      button {
        border: none;
        border-radius: 20px;
        background-color: red;
        color: #fff;
        padding: 2px 15px;
        position: absolute;
        right: 20px;
      }
    }
  }
}
</style>